const db = wx.cloud.database()
const _ = db.command
Page({
  data: {
    // first: '学校',
    // second: '类型',
    // currentTab: 0,
	pickerdata: { all: "全部" ,type:"全部类型"},
	skip: 0,
	matchs:[]
  },
//   tabNav: function(e){
//     this.setData({
//       currentTab: e.currentTarget.dataset.current
//     })
//   },
//   hidenav:function(e){
//     if(this.data.displays=="none")
//     {
//       this.setData({
//         displays: "block",
//       })
//     }
//     else
//     {
//       this.setData({
//         displays: "none",
//       })
//     } 
//   },

// hideNav: function () {
//   this.setData({
//     displays: "none"
//   })
// },
	jumponNewTeam(e){
		wx.navigateTo({
			url: '/pages/newMatch/newMatch',
		})
	},
	getPicker(e){
		console.log(e.detail)
		let pickerdata = e.detail
		let area = ''
		if (pickerdata.all!= undefined){
			area = pickerdata.all
		}
		if (pickerdata.province != undefined) {
			area = pickerdata.province
		}
		if (pickerdata.city != undefined) {
			area = pickerdata.city
		}
		if (pickerdata.school != undefined) {
			area = pickerdata.school
		}
		this.setData({
			skip: 0,
			area:area
		})
		
		if (pickerdata.type == "全部类型") {
			//全部类
			db.collection('match').where({
				area: area
			}).limit(18).skip(this.data.skip).get().then(res => {
				let matchs = res.data
				this.setData({
					skip: 18,
					matchs: matchs,
					pickerdata: e.detail
				})
			})
			return
		}else{
			//单个类
			db.collection('match').where({
				area:area,
				type: pickerdata.type
			}).limit(18).skip(this.data.skip).get().then(res => {
				console.log(res)
				let matchs = res.data
				this.setData({
					skip: 18,
					matchs: matchs,
					pickerdata: e.detail
				})
			})
			return
		}
	},
	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {
		if (this.data.pickerdata.type == "全部类型") {
			//全部类
			db.collection('match').where({
				area: this.data.area
			}).limit(18).skip(this.data.skip).get().then(res => {
				let matchs = this.data.matchs.concat(res.data)
				this.setData({
					skip: this.data.skip + 18,
					matchs: matchs
				})
			})
			return
		} else {
			//单个类
			db.collection('match').where({
				area: this.data.area,
				type: this.data.pickerdata.type
			}).limit(18).skip(this.data.skip).get().then(res => {
				console.log(res)
				let matchs = this.data.matchs.concat(res.data)
				this.setData({
					skip: this.data.skip + 18,
					matchs: matchs
				})
			})
			return
		}
	},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
	  if (this.data.pickerdata.all != undefined) {
		  db.collection('match').limit(18).skip(this.data.skip).get().then(res => {
			  let matchs = this.data.matchs.concat(res.data)
			  this.setData({
				  skip: 18,
				  matchs: matchs
			  })
		  })
		  return
	  }
  }

})